
package com.airplane.hotdiscuss.util;

import android.util.Config;
import android.util.Log;

import java.util.Hashtable;

public class MyLogger {
    private static final boolean isLoggerEnable = Config.DEBUG;
    private static final String LOG_TAG = "[HotDiscuss]";
    private static Hashtable<String, MyLogger> mLoggerTable;

    static {
        mLoggerTable = new Hashtable<String, MyLogger>();
    }

    private String mClassName;

    public MyLogger(String className) {
        mClassName = className;
    }

    public static MyLogger getLogger(String className) {
        MyLogger logger = (MyLogger) mLoggerTable.get(className);
        if (logger == null) {
            logger = new MyLogger(className);
            mLoggerTable.put(className, logger);
        }

        return logger;
    }

    public void v(String log) {
        if (isLoggerEnable) {
            Log.v(LOG_TAG, "{Tread:" + Thread.currentThread().getName() + "}" + "[" + mClassName
                    + "]:" + log);
        }
    }

    public void d(String log) {
        if (isLoggerEnable) {
            Log.d(LOG_TAG, "{Tread:" + Thread.currentThread().getName() + "}" + "[" + mClassName
                    + "]:" + log);
        }
    }

    public void i(String log) {
        if (isLoggerEnable) {
            Log.i(LOG_TAG, "{Tread:" + Thread.currentThread().getName() + "}" + "[" + mClassName
                    + "]:" + log);
        }
    }

    public void w(String log) {
        if (isLoggerEnable) {
            Log.w(LOG_TAG, "{Tread:" + Thread.currentThread().getName() + "}" + "[" + mClassName
                    + "]:" + log);
        }
    }

    public void e(String log) {
        if (isLoggerEnable) {
            Log.e(LOG_TAG, "{Tread:" + Thread.currentThread().getName() + "}" + "[" + mClassName
                    + "]:" + log);
        }
    }

    public void e(String log, Throwable tr) {
        if (isLoggerEnable) {
            Log.v(LOG_TAG, "{Tread:" + Thread.currentThread().getName() + "}" + "[" + mClassName
                    + "]:" + log + "\n" + Log.getStackTraceString(tr));
        }

    }
}
